﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Silverlight.Navigation.Favorites
{
    /// <summary>
    /// Responsible for managing a user's favorites.
    /// </summary>
    public abstract class FavoritesManager
    {
        #region Fields

        private FavoriteItemCollection _favoriteItems;

        #endregion

        #region Properties

        /// <summary>
        /// The user's home page.
        /// </summary>
        public abstract FavoriteItem HomePage { get; set; }

        /// <summary>
        /// All of the user's favorites.
        /// </summary>
        public FavoriteItemCollection FavoriteItems
        {
            get
            {
                if (_favoriteItems == null)
                    _favoriteItems = new FavoriteItemCollection();

                return _favoriteItems;
            }

            set { _favoriteItems = value; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds a favorite item.
        /// </summary>
        /// <param name="name">Name of the favorite.</param>
        /// <param name="uri">Uri of the favorite.</param>
        public void Add(string name, string uri)
        {
            this.Add(new FavoriteItem { Name = name, Uri = uri });
        }

        /// <summary>
        /// Adds a favorite item.
        /// </summary>
        /// <param name="favoriteItem">Item to add.</param>
        public void Add(FavoriteItem favoriteItem)
        {
            FavoriteItems.Add(favoriteItem);
            this.Save();
        }

        /// <summary>
        /// Removes a favorite item.
        /// </summary>
        /// <param name="favoriteItem">Item to remove.</param>
        public void Remove(FavoriteItem favoriteItem)
        {
            FavoriteItems.Remove(favoriteItem);
            this.Save();
        }

        /// <summary>
        /// Loads the favorite items.
        /// </summary>
        public abstract void Load();

        /// <summary>
        /// Saves the favorite items.
        /// </summary>
        public abstract void Save();

        #endregion
    }
}
